﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Web.Areas.MyAdams.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class ClassifiedsController : Controller
    {
        [AppendLayoutModel]
        public ActionResult Index()
        {
            var memberid = User.Identity.Name.ToInt();
            var model = MyAdams.Logic.Classifieds.Index.PageLoad(memberid);
            return View(Adams.Web.Controllers.MobileCheck.IsMobile() ? "Index.Mobile" : "Index", model);
        }

        public JsonResult Renew(int postingId)
        {
            var memberid = User.Identity.Name.ToInt();
            var model = MyAdams.Logic.Classifieds.Index.Renew(memberid, postingId);
            return Json(model);
        }

        public JsonResult Remove(int postingId)
        {
            var memberid = User.Identity.Name.ToInt();
            var model = MyAdams.Logic.Classifieds.Index.Remove(memberid, postingId);
            return Json(model);
        }

        [AppendLayoutModel]
        public ActionResult Create(int id)
        {
            var memberid = User.Identity.Name.ToInt();
            var model = MyAdams.Logic.Classifieds.Create.PageLoad(memberid, id);
            return View(Adams.Web.Controllers.MobileCheck.IsMobile() ? "Create.Mobile" : "Create", model);
        }

        public JsonResult GetCategoriesByType(int typeId)
        {
            var model = MyAdams.Logic.Classifieds.Create.GetCategoriesByType(typeId);
            return Json(model);
        }

        public JsonResult Save(MyAdams.Models.Classifieds.Create.FormInput input)
        {
            input.MemberID = User.Identity.Name.ToInt();
            var model = MyAdams.Logic.Classifieds.Create.Save(input);
            return Json(model);
        }
    }
}